package com.uchiha.nova.mainService.wrapper;

import com.uchiha.nova.core.model.entity.ChinaAreaEntity;
import com.uchiha.nova.core.model.vo.ChinaAreaVO;
import com.uchiha.nova.core.tool.node.ForestNodeMerger;
import com.uchiha.nova.core.tool.support.BaseEntityWrapper;
import com.uchiha.nova.core.tool.util.BeanUtil;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 行政设置 包装类,返回视图层所需的字段
 *
 * @author Chill
 */
public class ChinaAreaWrapper extends BaseEntityWrapper<ChinaAreaEntity, ChinaAreaVO>  {

	public static ChinaAreaWrapper build() {
		return new ChinaAreaWrapper();
 	}

	@Override
	public ChinaAreaVO entityVO(ChinaAreaEntity chinaAreaEntity) {
		ChinaAreaVO vo = new ChinaAreaVO();
		BeanUtil.copyProperties(chinaAreaEntity,vo);
		return vo;
	}

	public List<ChinaAreaVO> listNodeVO(List<ChinaAreaEntity> list) {
		List<ChinaAreaVO> collect = list.stream().map(dict -> {
			ChinaAreaVO vo = new ChinaAreaVO();
			BeanUtil.copyProperties(dict,vo);

			return vo;
		}).collect(Collectors.toList());
		return ForestNodeMerger.merge(collect).get(0).getChildren();
	}

}
